﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Pongster
{
    public class LinkLabel : Control
    {
        public Color selectedColor = Color.DodgerBlue;
        public Rectangle areaRect;
                
        public Color SelectedColor
        {
            get { return selectedColor; }
            set { selectedColor = value; }
        }

        public Rectangle AreaRect
        {
            get { return areaRect; }
            set { areaRect = value; }
        }

        public LinkLabel()
        {
            TabStop = true;
            HasFocus = false;
            Position = Vector2.Zero;
        }

        public override void Update(GameTime gameTIme)
        {
            areaRect = new Rectangle((int)Position.X - (int)Origin.X, (int)Position.Y, (int)SpriteFont.MeasureString(Text).X, (int)SpriteFont.MeasureString(Text).Y);

            if (areaRect.Contains(InputHandler.MousePoint) && InputHandler.LeftMouseClick())
            {
                base.OnSelected(null);
            }                            
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            if (hasFocus)
                //  spriteBatch.DrawString(SpriteFont, Text, Position, selectedColor);
                spriteBatch.DrawString(SpriteFont, Text, Position, selectedColor, Rotation, Origin, Scale, SpriteEffects.None, 1f);
            else
                // spriteBatch.DrawString(SpriteFont, Text, Position, Color);
                spriteBatch.DrawString(SpriteFont, Text, Position, Color, Rotation, Origin, Scale, SpriteEffects.None, 1f);

        }

        public void Draw(SpriteBatch spriteBatch, Color color)
        {
            spriteBatch.DrawString(SpriteFont, Text, Position, color, Rotation, Origin, Scale, SpriteEffects.None, 1f);
        }

        public override void HandleInput()
        {
            if (!HasFocus)
                return;

            if (InputHandler.KeyReleased(Keys.Enter) || InputHandler.KeyReleased(Keys.Space))
                base.OnSelected(null);            
        }

    }
}
